package com.ternnetwork.core.accesscontroll.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;

import com.ternnetwork.persistence.repository.BaseRepository;
import com.ternnetwork.core.accesscontroll.entity.Role;

public interface RoleRepository extends BaseRepository<Role, Long> {
	
	/**
	 * 按角色代码称统计
	 * @param code
	 * @return
	 */
	@Query("select count(1) from Role where nameEn=?1")
	Long getCountByCode(String code);
	
	/**
	 * 排除传入ID，按角色代码称统计
	 * @param code
	 * @param excludeId
	 * @return
	 */
	@Query("select count(1) from Role where nameEn=?1 and id!=?2")
	Long getCountByCodeAndExcludeId(String code,Long excludeId);
	
	/**
	 * 按类别查找
	 * @param category
	 * @return
	 */
	@Query("from Role where category=?1")
    List<Role> findAllByCategory(String category);
	
	/**
	 * 按代码查找
	 * @param code
	 * @return
	 */
	@Query("from Role where nameEn=?1")
	List<Role> findByCode(String code);
	
	/**
	 * 查找所有
	 */
	@Query("from Role order by id asc")
	List<Role> findAll();

}
